package exercise;

import JZOffer.TreeNode;

import java.util.*;

public class LCR151 {
    public List<List<Integer>> decorateRecord(TreeNode root) {
        boolean flg = true;
        Queue<TreeNode> queue = new LinkedList<>();
        List<List<Integer>> ans = new ArrayList<>();

        if (root == null) {
            return new ArrayList<>();
        }
        queue.offer(root);

        while (!queue.isEmpty()) {
            List<Integer> list = new ArrayList<>();
            int sz = queue.size();

            while (sz > 0) {
                TreeNode node = queue.poll();
                list.add(node.val);
                if (node.left != null) {
                    queue.offer(node.left);
                }
                if (node.right != null) {
                    queue.offer(node.right);
                }
                sz--;
            }
            if (!flg) {
                Collections.reverse(list);
                flg = true;
            } else {
                flg = false;
            }
            ans.add(list);
        }
        return ans;
    }

    public static void main(String[] args) {
        LCR151 lcr151 = new LCR151();
        TreeNode node = new TreeNode(1);
        node.left = new TreeNode(2);
        node.right = new TreeNode(3);
        node.left.left = new TreeNode(4);
        node.left.right = new TreeNode(5);


        List<List<Integer>> list = lcr151.decorateRecord(node);
        System.out.println(12);
    }
}
